//
//  RCMerchantPhotoUploadDataModel.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-10-1.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCMerchantPhotoUploadDataModel.h"
#import "FrameworkRelativeDefines.h"
#import "NSArray+EX.h"

@implementation RCMerchantPhotoUploadItem

@synthesize itemID = _itemID;
@synthesize itemName = _itemName;
@synthesize itemParentID = _itemParentID;

-(id)init{
    self = [super init];
    if (self) {
        _itemID = nil;
        _itemName = nil;
        _itemParentID = nil;
    }
    return self;
}

-(void)dealloc{
    self.itemParentID = nil;
    self.itemID = nil;
    self.itemName = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    RCMerchantPhotoUploadItem *retObject = nil;
    retObject = [[RCMerchantPhotoUploadItem alloc]init];
    if (nil == retObject) {
        return nil;
    }
    retObject.itemID = [data stringValueForKey:@"id" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.itemName = [data stringValueForKey:@"name" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.itemParentID = [data stringValueForKey:@"parentid" defaultValue:nil operation:NSStringOperationTypeTrim];
    return [retObject autorelease];
}

@end

@implementation RCMerchantPhotoUploadDataModel

@synthesize itemListArray = _itemListArray;

-(id)init{
    self = [super init];
    if (self) {
        _itemListArray = nil;
    }
    return self;
}
-(void)dealloc{
    self.itemListArray = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    NSArray *dictArray = [data arrayValueForKey:@"data" defaultValue:nil];
    if (nil == dictArray) {
        return nil;
    }
    RCMerchantPhotoUploadDataModel *retObject = nil;
    retObject = [[RCMerchantPhotoUploadDataModel alloc]init];
    if (nil == retObject) {
        return nil;
    }
    
    NSMutableArray *tempArray = [[NSMutableArray alloc]initWithCapacity:[dictArray count]];
    for (int i = 0; i < [dictArray count]; i++) {
        NSDictionary *itemDict = [dictArray safeObjectAtIndex:i];
        if (nil == itemDict) {
            continue;
        }
        RCMerchantPhotoUploadItem *item = [RCMerchantPhotoUploadItem parseDataFromJSON:itemDict];
        if (nil == item) {
            continue;
        }
        [tempArray addObject:item];
    }
    retObject.itemListArray = [NSArray arrayWithArray:tempArray];
    [tempArray release];
    
    return [retObject autorelease];
}

@end
